package com.fengye.algorithms.huawei.dp;

import java.util.Scanner;

/**
 * https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1?tpId=37&tqId=21255&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
 * @Author fengye
 * @Date 2023/4/7 10:44
 **/
public class PasswordSubMain {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String enc = in.nextLine();
            boolean[][] dp = new boolean[enc.length()][enc.length()];
            char[] encChar = enc.toCharArray();
            String res = "";
            /**
             * 动态规划，最长回文
             */
            for(int i=0;i<enc.length(); i++) {
                for(int j=i;j>=0;j--) {
                    // 一位字符是回文
                    if(i-j < 2 && encChar[i] == encChar[j]) {
                        dp[i][j] = true;
                        // 两边相等，中间是回文，也是回文
                    }else if(encChar[j] == encChar[i] && dp[i - 1][j + 1]) {
                        dp[i][j] = true;
                    }
                    // 取出最长回文
                    if(dp[i][j] && i-j+1 > res.length()) {
                        res = enc.substring(j, i+1);
                    }
                }
            }
            System.out.println(res.length());
        }
    }
}
